package com.smh.a04SetDemo1;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class SetDemo1 {
    public static void main(String[] args) {

        Set<String> s = new HashSet<>();
        System.out.println(s.add("sadad"));
        System.out.println(s.add("sadad"));
        System.out.println(s.add("1"));
        System.out.println(s.add("3"));
        System.out.println(s.add("2"));
        //元素不能重复
        System.out.println(s);
        System.out.println("----------------");

        Iterator<String> it = s.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }
        System.out.println("----------------");

        for (String string : s) {
            System.out.println(string);
        }
        System.out.println("----------------");
        s.forEach(str->{
            System.out.println(str);
        });
        System.out.println("-----------");



    }
}
